(function(i) {
    var t = setInterval(function () {
        if (document.readyState=="loaded"||document.readyState=="complete")
            clearInterval(t), i();
        }, 0);
})(loadCoolSearch);

var token;

function loadCoolSearch() {
    var coolJsFile="coolSearch.js";
    if(this!=top) coolJsFile="coolFrame.js";
    token="jsfile"+Math.random();
    safari.self.addEventListener("message", readJs, false);
    safari.self.tab.dispatchMessage("load_js", {token:token, file:coolJsFile});
}

function readJs(event) {
	if(event.name!="js_file") return;
	var msg=event.message;
    if(msg.token!=token) return;
    window.eval(msg.file);
    safari.self.removeEventListener("message", readJs, false);
}